package com.zretc.blog.controller;

import com.zretc.api.pojo.Blog;
import com.zretc.api.pojo.Comment;
import com.zretc.blog.service.CommentService;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/blog")
public class CommentController {
    @Autowired
    CommentService commentService;

    @RequestMapping("/addComment")
    public RespResult addComment(@RequestBody Comment comment){
        commentService.addComment(comment);
        return R.success("评论成功");
    }

    @GetMapping("/getCommentList")
    public RespResult getCommentList(Integer blogId){
        List<Comment> list = commentService.getCommentList(blogId);
        return R.success(list);
    }

    @GetMapping("/getCommentByUser")
    public RespResult getCommentByUser(Integer commentatorId){
        List<Comment> list = commentService.getCommentByUser(commentatorId);
        return R.success(list);
    }

    @GetMapping("/deleteComment")
    public  RespResult deleteComment(Integer id){
        commentService.deleteComment(id);
        return R.success("删除评论成功");
    }

    @RequestMapping("/setCommentPass")
    public RespResult setCommentPass(Comment comment){
        commentService.setCommentPass(comment);
        return R.success("审核完成");
    }

    @RequestMapping("/setCommentDeleted")
    public RespResult setCommentDeleted(Comment comment){
        commentService.setCommentDeleted(comment);
        return R.success("隐藏/显示完成");
    }

    @GetMapping("/deleteCommentByBlog")
    public  RespResult deleteCommentByBlog(Integer blogId){
        commentService.deleteCommentByBlog(blogId);
        return R.success("删除评论成功");
    }

    @GetMapping("/likeComment")
    public RespResult likeComment(Integer id){
        commentService.likeComment(id);
        return R.success("点赞评论成功");
    }

    @GetMapping("/getCommentById")
    public  RespResult getCommentById(Integer id){
        Comment comment = commentService.getCommentById(id);
        return R.success(comment);
    }
}
